<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>智能营销线索</title>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/bc/css/clue.css"/>
<style type="text/css">
.top-line {
    position: relative;
    left: 100px;
    width: 800px;
    height: 50px;
    flex-shrink: 0;
    border: 1px solid #03a9f4;
    border-bottom: 0;
}
.model-height {
    height: 180px;
}
.item-block {
    position: relative;
    width: 200px;
    padding: 15px;
    color: #fff;
    flex-shrink: 0;
    border-radius: 3px;
}
.bg1 {
    background: #ffc105;
}
.item-block h5 {
    font-size: 16px;
    margin-top: 3px;
    color: #fff;
    text-decoration: underline;
}
.item-block .model-con {
    position: absolute;
    bottom: 10px;
}
.info-hover {
    position: absolute;
    width: 16px;
    height: 18px;
    background: url(../images/icon_6.png);
    background-size: cover;
    bottom: 9px;
    right: 8px;
}
.item-block ul {
    display: none;
    position: absolute;
    color: #000;
    padding: 25px 20px;
    line-height: 24px;
    z-index: 10;
    background: url(../images/pop_bg.png) no-repeat;
    width: 262px;
    height: 122px;
    top: 180px;
    left: 50px;
}
.item-block ul li {
    color: #666;
}
.line-block1 {
    height: 90px;
    border-bottom: 1px solid #03a9f4;
    border-radius: 0;
}
.item-block {
    position: relative;
    width: 200px;
    padding: 15px;
    color: #fff;
    flex-shrink: 0;
    border-radius: 3px;
}
.prism1 {
    position: absolute;
    top: 54px;
    left: 30px;
    background: #b9d0df;
    width: 110px;
    height: 70px;
    color: #fff;
    -webkit-clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
    -moz-clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
    transition: 1s clip-path;
    padding: 15px 26px;
    text-align: center;
}
.bg2 {
    background: #fd7167;
}
.item-block .date-left1 {
    top: 65px;
    left: -38px;
}
.item-block .date {
    width: 50px;
    height: 50px;
    line-height: 48px;
    text-align: center;
    border-radius: 30px;
    border: 2px solid #fff;
    background: #ff7469;
    position: absolute;
    top: -36px;
    left: 75px;
}
.bg3 {
    background: #03a9f4;
}
</style>
</head>
<body class="gray-bg">
<div class="container-fluid">
	<div class="row activity1">
	    <div class="col-sm-12">
	        <div class="ibox float-e-margins">
	            <div class="ibox-title">
	                <h5><span id="activityCount">0</span> 条线索源于智能营销-拉新模型</h5>
	                 <div class="ibox-tools">
	                    <a>编辑</a>
	                    <a>启用</a>
	                    <a>复制</a>
	                    <a>删除</a>
	                </div>
	            </div>
	            <div class="ibox-content">
	            	<div class="pad2">
	                    <div class="k_box">
	                        <div style="display:flex;">
	                            <div class="top-line"></div>
	                        </div>
	                        <div style="display:flex;">
	                            <div class="item-block bg1 model-height">
	                                <h5>2017喀拉库</h5>
	                                <div class="model-con">
	                                    <p>打开次数：<span>1000</span></p>
	                                    <p>转发次数：<span>100</span></p>
	                                    <p>提交表单数：<span>1000</span></p>
	                                    <p>核销人数：<span>10</span></p>
	                                    <p>累计消费金额：<span>1000</span></p>
	                                </div>
	                                <div class="info-hover"></div>
	                                <ul>
	                                    <li>发送方式 &nbsp; <span>短信</span></li>
	                                    <li>发送对象 &nbsp; <span>老客户&nbsp;&nbsp;&nbsp;&nbsp;20</span></li>
	                                    <li>发送时间 &nbsp; <span>2017-07-21&nbsp;&nbsp;&nbsp;&nbsp;12：12</span></li>
	                                </ul>
	                            </div>
	                            <div class="item-block line-block1">
	                                <div class="prism1">参加上<br />一次活动</div>
	                            </div>
	                            <div class="item-block bg2 model-height">
	                                <h5>卡拉斯科</h5>
	                                <div class="date date-left1">立刻</div>
	                                <div class="model-con">
	                                    <p>打开次数：<span>1000</span></p>
	                                    <p>转发次数：<span>100</span></p>
	                                    <p>提交表单数：<span>1000</span></p>
	                                    <p>核销人数：<span>10</span></p>
	                                    <p>累计消费金额：<span>1000</span></p>
	                                </div>
	                                <div class="info-hover"></div>
	                                <ul>
	                                    <li>发送方式 &nbsp; <span>短信</span></li>
	                                    <li>发送对象 &nbsp; <span>老客户&nbsp;&nbsp;&nbsp;&nbsp;20</span></li>
	                                    <li>发送时间 &nbsp; <span>2017-07-21&nbsp;&nbsp;&nbsp;&nbsp;12：12</span></li>
	                                </ul>
	                            </div>
	                            <div class="item-block"></div>
	                            <div class="item-block bg3 model-height">
	                                <h5>任务大作战 0元吃烤鸭</h5>
	                                <div class="date">30</div>
	                                <div class="model-con">
	                                    <p>打开次数：<span>1000</span></p>
	                                    <p>转发次数：<span>100</span></p>
	                                    <p>提交表单数：<span>1000</span></p>
	                                    <p>核销人数：<span>10</span></p>
	                                    <p>累计消费金额：<span>1000</span></p>
	                                </div>
	                                <div class="info-hover"></div>
	                                <ul>
	                                    <li>发送方式 &nbsp; <span>短信</span></li>
	                                    <li>发送对象 &nbsp; <span>老客户&nbsp;&nbsp;&nbsp;&nbsp;20</span></li>
	                                    <li>发送时间 &nbsp; <span>2017-07-21&nbsp;&nbsp;&nbsp;&nbsp;12：12</span></li>
	                                </ul>
	                            </div>
	                        </div>
	                    </div>
	            	</div>
	            	
	            	
	            	<div id="nothing" style="text-align: center;display: none;">
           				<img src="<%=path%>/images/icon_hd.png">
           				<p>您还没有活动 <a href="<%=path%>/api/bm/ui/createActivity1">去创建活动&gt;</a></p>
           			</div>
	            </div>
	        </div>
	    </div>
	</div>
	
	<div class="row activity2">
	    <div class="col-sm-12">
	        <div class="ibox float-e-margins">
	            <div class="ibox-title">
	               <ul class="ulH">
						<li>暂无活动</li>
					</ul>
	            </div>
	            <div class="ibox-content">
	            	<div class="tabs-container">
				        <ul class="nav nav-tabs">
				            <li class="active"><a data-toggle="tab" href="#tab-1_1" aria-expanded="true">新线索</a></li>
				            <li class=""><a data-toggle="tab" href="#tab-2_1" aria-expanded="false">客户行为</a></li>
				            <li class=""><a data-toggle="tab" href="#tab-3_1" aria-expanded="false">客户资料</a></li>
				            <li class=""><a data-toggle="tab" href="#tab-4_1" aria-expanded="false">验证核销</a></li>
				        </ul>
				        <div class="tab-content">
				            <div id="tab-1_1" class="tab-pane active">
				                <div class="panel-body">
				                </div>
				            </div>
				            <div id="tab-2_1" class="tab-pane">
				                <div class="panel-body">
				                    <strong>移动设备优先</strong>
				                    <p>在 Bootstrap 2 中，我们对框架中的某些关键部分增加了对移动设备友好的样式。而在 Bootstrap 3 中，我们重写了整个框架，使其一开始就是对移动设备友好的。这次不是简单的增加一些可选的针对移动设备的样式，而是直接融合进了框架的内核中。也就是说，Bootstrap 是移动设备优先的。针对移动设备的样式融合进了框架的每个角落，而不是增加一个额外的文件。</p>
				                </div>
				            </div>
				            <div id="tab-3_1" class="tab-pane">
				                <div class="panel-body">
				                    <table class="table table-hover">
					                	<thead>
					                        <tr>
					                            <th>姓名</th>
					                            <th>行为</th>
					                            <th>来源</th>
					                            <th>时间</th>
					                            <th>操作</th>
					                        </tr>
					                    </thead>
					                    <tbody>
					                    </tbody>
					                </table>
				                </div>
				            </div>
				            <div id="tab-4_1" class="tab-pane">
				                <div class="panel-body">
				                    <strong>移动设备优先</strong>
				                    <p>在 Bootstrap 2 中，我们对框架中的某些关键部分增加了对移动设备友好的样式。而在 Bootstrap 3 中，我们重写了整个框架，使其一开始就是对移动设备友好的。这次不是简单的增加一些可选的针对移动设备的样式，而是直接融合进了框架的内核中。也就是说，Bootstrap 是移动设备优先的。针对移动设备的样式融合进了框架的每个角落，而不是增加一个额外的文件。</p>
				                </div>
				            </div>
				        </div>
				    </div>
	            </div>
	        </div>
	    </div>
	</div>
</div>
</body>
<script type="text/javascript" src="<%=path%>/hplus/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/bootstrap.min.js"></script>

<script type="text/javascript" src="<%=path%>/bc/js/clue_title.js"></script>
<script type="text/javascript" src="<%=path%>/js/page.js"></script>
<script type="text/javascript" src="<%=path%>/bm/js/jquery.cookie.js"></script>
<script type="text/javascript" src="<%=path%>/js/custom.js"></script>
<script type="text/javascript" src="<%=path%>/js/dialog-plus.js"></script>
<script type="text/javascript">
var path = '<%=path%>';
var startIndex = 0;
var pageSize = 10;
var keyWord = "";
var currentPage = 1;
var pageCount = 0;
var listIndex = 0;	//这个用于所要显示列表的索引；0(新线索)，1(客户行为)，2(客户资料)，3(验证核销)
var handleStatus = 0;	//处理状态；0(未处理)，1(已处理)
var activityId = 0;	//活动id
var activityIds = "";	//活动组，3个活动id

var customerId = 0;	//客户id
var actionId = 0;	//客户行为id
var clueWeiboId = 0;//微博线索id
var writeOffId = 0;	//核销id
var access_token=$.cookie('access_token');
var cid=$.cookie('cid');
var uid=$.cookie('uid');
var user_name = $.cookie('user_name');

$(function(){
	init();
	
	$(document).on('click','.s_all_title:eq(0)>li',function(){
        keyWord = $(this).attr("keyWord");
		activityId = $(this).attr("activityId");
        
        currentPage = 1;
		startIndex = 0;
        init();
    });
	
	$(document).on('click','.s_all_title:eq(1)>li',function(){
		var index = $(this).index();
		currentPage = 1;
		startIndex = 0;
		listIndex = index;
		if(index == 0){
			handleStatus = 0;
		}else if(index == 1){
			handleStatus = 1;
		}else{
			handleStatus = null;
		}
		
		$(".s_all:eq(1)>.s_all_title>li:eq("+index+")").addClass('s_all_on').siblings().removeClass();
        init();
    });
	
	/*聊天点击开始*/
	$(document).on("click",".s_icon_dialogue",function(){
		//初始化数据，全部设置0
		top.customerId = 0;
		top.actionId = 0;
		top.clueWeiboId = 0;
		top.writeOffId = 0;
		
		customerId = $(this).attr("customerId");
		actionId = $(this).attr("actionId");
		clueWeiboId = $(this).attr("clueWeiboId");
		writeOffId = $(this).attr("writeOffId");
		
		top.customerId = customerId;
		top.actionId = actionId;
		top.clueWeiboId = clueWeiboId;
		top.writeOffId = writeOffId;
		
		var d = top.dialog({
			fixed: true,
			zIndex: 10000,
			padding:0,
			width:1172,
			height:568,
			title:'沟通记录',
			url:"<%=path%>/api/customer_action/customerChatView",
			cancelDisplay: false,
			cancel: function () {
				if(top.customerChatChange == 1){
					top.customerChatChange = 0;
				}
				top.customerId = 0;
				top.actionId = 0;
				top.clueWeiboId = 0;
				return true;
			}
		});
		d.showModal();
	});
	/*聊天点击结束*/
});

function init(){
	getMarket();
	$.post("${pageContext.request.contextPath}/api/weibo/showfirstpage",function(data){
		data = eval(data);
		if(data.showstatus == 1){
			;
		}else if(data.showstatus == 0){
			$(".m_xmanage>a:eq(1)").css("display","none");
		}
	});
	
	$.post('<%=path%>/api/clue_customer/clue_smart_activity',{
		"startIndex":startIndex,"pageSize":pageSize,
		"keyWord":keyWord,"handleStatus":handleStatus,
		"listIndex":listIndex,"activityId":activityId,
		activityIds:activityIds
	},function(data){
		data = JSON.parse(data);
		
		/* setFirst(data.activity_name_list); */
		
		setSecond(data.activity_clue_list);
		
		page(data.totalCount);
		
		parent.changeFrameHeight();
	});
}

function setFirst(list){
	$(".s_all:eq(0)>.s_all_title").html('<li activityId="0" class="s_all_on" keyWord=""><a href="javascript:;">全部</a></li>');
	
	for ( var i = 0; i < list.length; i++) {
		var a = list[i];
		
		$(".s_all:eq(0)>.s_all_title").append('<li activityId="'+a.id+'" keyWord="'+a.name+'"><a href="javascript:;">'+a.name+'</a></li>');
	}
	
	if(list.length == 0){
		$(".s_container").html('<div class="s_clue"><p><span>0</span> 条线索源于智能营销</p><div class="k_empty_content"><img src="<%=path%>/bc/images/icon_zn.png"><p>您还没有智能营销模型 <a href="<%=path%>/api/bm/ui/createMarket?type=create" target="_parent">去创建智能营销&gt;</a></p></div></div>');
	}

	$(".s_all:eq(0)>.s_all_title>li[keyWord='"+keyWord+"']").addClass('s_all_on').siblings().removeClass();
}

function setSecond(list){
	if(listIndex == 0){
		list0(list);
	}else if(listIndex == 1){
		list1(list);
	}else if(listIndex == 2){
		list2(list);
	}else if(listIndex == 3){
		list3(list);
	}
}

/**
 * 	新线索
 */
function list0(list){
	var table = '<table><thead><tr><th>姓名</th><th>线索</th><th>来源</th><th>时间</th><th>操作</th></tr></thead><tbody></tbody></table>';
	$(".s_table_sq").html(table);
	
	for(var i = 0; i < list.length; i++){
		var a = list[i];
		var tr = '<tr><td><img style="height:50px;width:50px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? "<%=path%>/images/000head_pic.png" : a.avatar)+'" /><a href="javascript:;">'+a.name+'</a></td><td class="s_red">'+a.content+'</td><td>'+getSourceTitle(a.source)+'</td><td class="k_time">';
		
		var now = new Date();
		var old = new Date(a.createTimeStr);
		var m_date = parseInt((now.getTime() - old.getTime())/1000/60);
		if(m_date >= 100){
			m_date = a.createTimeStr;
		}else{
			m_date += "分钟前";
		}
		
		tr += m_date+'</td><td>'
			+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" onclick="delClueActivity('+a.id+')" class="s_icon_delect"></a></shiro:hasPermission>'
			+'<shiro:hasPermission name="customer_clue_chat_button"><a customerId="'+a.customerId+'" actionId="'+a.id+'" clueWeiboId="0" writeOffId="0" href="javascript:;" class="s_icon_dialogue"></a></shiro:hasPermission></td></tr>';
		$("table tbody").append(tr);
	}
}
/**
 * 	客户行为
 */
function list1(list){
	var table = '<table><thead><tr><th>姓名</th><th>行为</th><th>来源</th><th>时间</th><th>操作</th></tr></thead><tbody></tbody></table>';
	$(".s_table_sq").html(table);
	
	for(var i = 0; i < list.length; i++){
		var a = list[i];
		var tr = '<tr><td><img style="height:50px;width:50px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? "<%=path%>/images/000head_pic.png" : a.avatar)+'" /><a href="javascript:;">'+a.name+'</a></td><td class="s_red">'+a.content+'</td><td>'+getSourceTitle(a.source)+'</td><td class="k_time">';
		
		var now = new Date();
		var old = new Date(a.createTimeStr);
		var m_date = parseInt((now.getTime() - old.getTime())/1000/60);
		if(m_date >= 100){
			m_date = a.createTimeStr;
		}else{
			m_date += "分钟前";
		}
		
		tr += m_date+'</td><td>'
			+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" onclick="delClueActivity('+a.id+')" class="s_icon_delect"></a></shiro:hasPermission>'
			+'<shiro:hasPermission name="customer_clue_chat_button"><a customerId="'+a.customerId+'" actionId="'+a.id+'" clueWeiboId="0" writeOffId="0" href="javascript:;" class="s_icon_dialogue"></a></shiro:hasPermission></td></tr>';
		$("table tbody").append(tr);
	}
}
/**
 * 	客户资料
 */
function list2(list){
	var table = '<table><thead><tr><th>姓名</th><th>电话</th><th>邮箱</th><th>微博</th><th>微信</th><th>来源</th><th>操作</th></tr></thead><tbody></tbody></table>';
	$(".s_table_sq").html(table);
	
	for(var i = 0; i < list.length; i++){
		var a = list[i];
		var tr = '<tr><td><img style="height:50px;width:50px;" src="'+((a.avatar == null || a.avatar == undefined || a.avatar == "") ? "<%=path%>/images/000head_pic.png" : a.avatar)+'" /><a href="javascript:;">'+a.name+'</a></td><td>'+a.phone+'</td><td>'+a.email+'</td><td>'+a.weibo+'</td><td>'+a.weixin+'</td><td>'+a.source+'</td><td>'
			+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" class="s_icon_delect" onclick="delCustomer('+a.id+')"></a></shiro:hasPermission>'
			+'<shiro:hasPermission name="customer_clue_delete_button"><a href="javascript:;" class="edit" onclick="findByCustomerId('+a.id+')"></a></shiro:hasPermission>'
			+'<shiro:hasPermission name="customer_clue_chat_button"><a customerId="'+a.id+'" actionId="0" clueWeiboId="0" writeOffId="0" href="javascript:;" class="s_icon_dialogue"></a></shiro:hasPermission></td></tr>';
		$("table tbody").append(tr);
	}
}
function list3(list){
	var table = '<table><thead><tr><th>手机号</th><th>优惠券名</th><th>核销时间</th><th>编码</th><th>操作</th></tr></thead><tbody></tbody></table>';
	$(".s_table_sq").html(table);
	if(list != null){
		for(var i = 0; i < list.length; i++){
			var a = list[i];
			var tr = '<tr id="writeOffLine'+a.coupon_code+'"><td>'+a.mobile+'</td><td>'+a.coupon_name+'</td><td>'+a.w_time+'</td><td>'+a.coupon_code+'</td><td>'
				+'<em cd="'+a.coupon_code+'" couponId="'+a.coupon_id+'" acid="'+activityId+'" cuid="'+a.customer_id+'" class="k_fhx">反核销</em></td></tr>';
			$("table tbody").append(tr);
		}
	}
}

function getSourceTitle(source){
	var title;
	switch (source) {
	case "1":
		title="微博";
		break;
	case "2":
		title="微信";
		break;
	case "3":
		title="QQ";
		break;
	case "4":
		title="活动";
		break;
	case "5":
		title="pc网页";
		break;
	case "6":
		title="短信";
		break;
	default:
		title="未知";
		break;
	}
	return title;
	
}

function delClueActivity(id){
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		$.post("<%=path%>/api/clue_customer/delClueActivity",{clueActivityId:id},function(data){
			init();
			$(".j_popup_box").hide();
		});
	});
}

function delCustomer(id){
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		$.post("<%=path%>/api/custome/delectCustomer",{id:id},function(data){
			init();
			$(".j_popup_box").hide();
		});
	});
}

var clueNum;

//获取智能营销
function getMarket(){
	html='';
	var url = "<%=path%>/api/smart_market/queryHomeMarket";
	$.ajax({
		async:false,
		url:url,
		type:"POST",
		dataType:"text",
		data:{
			"access_token" : access_token,
			"cid" : cid,
			"uid" : uid
		},
		success:function(data){
			var datas = JSON.parse(data);
			activityIds = datas.data.activitys;
			if(datas.error_code=="0"){
				clueNum=datas.clueNum;
				setMarketHtml(datas.data);
			}else{
				
			}
		}
	});
}

function setMarketHtml(data){
		console.log(data);
		/* var activityData=JSON.parse(data[i].activityData); */
		setFirst(data.activityData);
		var activity1=data.activityData[0];
		var activity2=data.activityData[1];
		var activity3=data.activityData[2];
		g_activity1 = activity1.id;
		g_activity2 = activity2.id;
		g_activity3 = activity3.id;
		//解析活动二
		var send_time1= JSON.parse(activity1.send_time);
		var send_time2= JSON.parse(activity2.send_time);
		var send_time3= JSON.parse(activity3.send_time);
		var send_obj1= JSON.parse(activity1.send_object);
		var send_obj2= JSON.parse(activity2.send_object);
		var send_obj3= JSON.parse(activity3.send_object);
		var activity_send_time1=getSendTime(send_time1);
		var activity_send_time2=getSendTime(send_time2);
		var activity_send_time3=getSendTime(send_time3);
		
		var activity_send_obj1=getSendObj(send_obj1);
		var activity_send_obj2=getSendObj(send_obj2);
		var activity_send_obj3=getSendObj(send_obj3);
		
		var behavior_rule2=getBehaviorRule(activity2.behavior_rule);
		var behavior_rule3=getBehaviorRule(activity3.behavior_rule);
		
		
		
		var html='';
		
		html+='<div class="item-bottom top-title">';
		html+='<p><span>'+clueNum+'</span> 条线索源于智能营销-'+data.name+'</p>';
		html+='<div class="k_right"> ';
		/* html+='<input type="checkbox" name="firstpage" value="1" style="margin:0;">首页显示</label>'; */
		html+='<a target="_parent" href="javascript:;" market_id='+data.market_id+' processDefintionId='+data.definition_id+' class="edit_market">编辑</a>';
		html+='<a target="_parent" id="manageId'+data.market_id+'" href="javascript:;" market_id='+data.market_id+' activity_id='+activity1.id+' rule_id='+activity1.rule_id+' status='+data.status+' processDefintionId='+data.definition_id+'  '+(data.status==1?"class='manage_market'>停用":"class='manage_market k_red'>启用")+'</a>';
		html+='<a target="_parent" href="javascript:;" market_id='+data.market_id+' processDefintionId='+data.definition_id+' class="copy_market">复制</a></div></div>';
		html+='<div class="k_box">';
		html+=' <div style="display:flex;">';
		html+=' <div class="top-line"></div></div>';
		html+='<div style="display:flex;">';
		html+=' <div class="item-block bg1 model-height">';
		html+='<a target="_parent" style="text-decoration:underline;" href="<%=path%>/view/ui/activityDetail?type=1&activity_id='+activity1.id+'"><font color=white>'+activity1.name+'</font></a>';
		html+='<div class="model-con">';
		html+='<p>打开次数：<span>'+activity1.browse_number+'</span></p>';
		html+='<p>转发次数：<span>'+activity1.browse_number+'</span></p>';
		html+='<p>提交表单数：<span>'+activity1.submit_numer+'</span></p>';
		html+='<p>核销人数：<span>'+activity1.write_off_num+'</span></p>';
		html+='<p>累计消费金额：<span>'+activity1.consumption_amount+'</span></p></div>';
		html+='<div class="info-hover"></div>';
		html+='<ul><li>发送方式 &nbsp; <span>'+getSendType(activity1.send_type)+'</span></li>';
		html+='<li>发送对象 &nbsp; <span>'+activity_send_obj1+'</span></li>';
		html+='<li>发送时间 &nbsp; <span>'+activity_send_time1+'</span></li></ul></div>';
		html+='<div class="item-block line-block1">';
		html+='<i class="into s_into"></i><div class="prism1">'+behavior_rule2+'</div><i class="into"></i></div>';
		html+='<div class="item-block bg2 model-height">';
		html+='<a target="_parent" style="text-decoration:underline;" href="<%=path%>/view/ui/activityDetail?type=1&activity_id='+activity2.id+'"><font color=white>'+activity2.name+'</font></a>';
		html+='<div class="date date-left1" title="'+activity_send_time2+'" style="white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow: hidden;">'+activity_send_time2+'</div>';
		html+='<div class="model-con">';
		html+='<p>打开次数：<span>'+activity2.browse_number+'</span></p>';
		html+='<p>转发次数：<span>'+activity2.browse_number+'</span></p>';
		html+='<p>提交表单数：<span>'+activity2.submit_numer+'</span></p>';
		html+='<p>核销人数：<span>'+activity2.write_off_num+'</span></p>';
		html+='<p>累计消费金额：<span>'+activity2.consumption_amount+'</span></p></div>';
		html+='<div class="info-hover"></div>';
		html+='<ul><li>发送方式 &nbsp; <span>'+getSendType(activity2.send_type)+'</span></li>';
		html+='<li>发送对象 &nbsp; <span>'+activity_send_obj2+'</span></li>';
		html+='<li>发送时间 &nbsp; <span>'+activity_send_time2+'</span></li></ul></div>';
		html+='<div class="item-block"></div>';
		html+='<div class="item-block bg3 model-height">';
		html+='<a target="_parent" style="text-decoration:underline;" href="<%=path%>/view/ui/activityDetail?type=1&activity_id='+activity3.id+'"><font color=white>'+activity3.name+'</font></a>';
		html+='<i class="into k_into"></i><div class="date" title="'+activity_send_time3+'" style="white-space:nowrap;text-overflow:ellipsis;-o-text-overflow:ellipsis;overflow: hidden;">'+activity_send_time3+'</div>';
		html+='<div class="model-con">';
		html+='<p>打开次数：<span>'+activity3.browse_number+'</span></p>';
		html+='<p>转发次数：<span>'+activity3.browse_number+'</span></p>';
		html+='<p>提交表单数：<span>'+activity3.submit_numer+'</span></p>';
		html+='<p>核销人数：<span>'+activity3.write_off_num+'</span></p>';
		html+='<p>累计消费金额：<span>'+activity3.consumption_amount+'</span></p></div>';
		html+='<div class="info-hover"></div>';
		html+='<ul><li>发送方式 &nbsp; <span>'+getSendType(activity3.send_type)+'</span></li>';
		html+='<li>发送对象 &nbsp; <span>'+activity_send_obj3+'</span></li>';
		html+='<li>发送时间 &nbsp; <span>'+activity_send_time3+'</span></li>';
		html+='</ul></div></div></div>';
		$('.pad2').html(html);
}

$(document).on('mouseover', '.info-hover', function() {
	$(this).next().show();
});
$(document).on('mouseleave', '.info-hover', function() {
	    $(this).next().hide();
});

//获取发送时间
function getSendTime(send_time){
	var activity_send_time;
	for (var key in send_time)
    {
        switch (key) {
		case "right_now":
			activity_send_time="立刻";
			break;
		case "distance_last_consume":
			activity_send_time="距离上一次消费"+send_time[key]+"天";
			break;
		case "distance_first_consume":
			activity_send_time="距离第一次消费"+send_time[key]+"天";
			break;
		case "distance_last_activity":
			activity_send_time="距离上一活动"+send_time[key]+"天";
			break;
		case "date":
			activity_send_time=send_time[key];
			break;
		case "birthday":
			activity_send_time="生日";
			break;
		default:
			activity_send_time="立刻";
			break;
		}
    }
	return activity_send_time;
}
//获取发送方式
function getSendType(sendType){
	var send_typeTemp=sendType.split(",");
	var send_type="";
	for(var i in send_typeTemp){
		switch (send_typeTemp[i]) {
		case "sms":
			send_type=send_type+","+"短信";
			break;
		case "email":
			send_type=send_type+","+"邮箱";
			break;
		case "weibo":
			send_type=send_type+","+"微博";
			break;

		default:
			break;
		}
		
	}
	send_type=send_type.replace(",","");
	return send_type;
	
}
//获取行为规则
function getBehaviorRule(behavior_rule){
	var rule;
	switch (behavior_rule) {
	case 0:
		rule="无";
		break;
	case 1:
		rule="参加上一活动";
		break;
	case 2:
		rule="未参加上一活动";
		break;
		rule="无";
	default:
		break;
	}
	return rule;
}
//获取发送对象
function getSendObj(send_obj){
	var obj="";
	for (var key in send_obj){
		console.log("--------------------->"+key);
		switch (key) {
		case "trading_hours":
			console.log(send_obj[key]);
			var temp1=send_obj[key].split(",");
			for(var i in temp1){
				if(temp1[i]=="old_customer"){
					obj=obj+","+"老客户";
				}else if(temp1[i]=="new_customer")
					obj=obj+","+"新客户";
			}
			obj=obj.replace(",","");
			break;
		case "trading_frequency":
			var temp2=send_obj[key].split(",");
			for(var i in temp2){
				if(temp2[i]=="visitor"){
					obj=obj+","+"过客";
				}else if(temp2[i]=="frquenter"){
					obj=obj+","+"常客";
				}else if(temp2[i]=="loyal"){
					obj=obj+","+"忠诚客户";
				}
			}
			obj=obj.replace(",","");
			break;
		case "trading_amount":
			var temp3=send_obj[key].split(",");
			for(var i in temp3){
				if(temp3[i]=="main"){
					obj=obj+","+"主力";
				}else if(temp3[i]=="general"){
					obj=obj+","+"一般";
				}else if(temp3[i]=="scattered"){
					obj=obj+","+"零散";
				}
					
			}
			obj=obj.replace(",","");
			break;
		case "loss_status":
			var temp4=send_obj[key].split(",");
			for(var i in temp4){
				if(temp4[i]=="loss"){
					obj=obj+","+"流失客户";
				}else if(temp4[i]=="no_loss"){
					obj=obj+","+"未流失客户";
				}
					
			}
			obj=obj.replace(",","");
			break;

		default:
			break;
		}
	return obj;
	}
}

//复制
$(document).on('click', '.copy_market', function() {
	var market_id=$(this).attr("market_id");
	window.parent.location.href = "<%=path%>/api/bm/ui/createMarket?type=copy&market_id="+market_id;
});

//编辑
$(document).on('click', '.edit_market', function() {
	var market_id=$(this).attr("market_id");
	window.parent.location.href = "<%=path%>/api/bm/ui/createMarket?type=edit&market_id="+market_id;
});
//启用停用
$(document).on('click', '.manage_market', function() {
	var market_id=$(this).attr("market_id");
	var status=$(this).attr("status");
	var processDefintionId=$(this).attr("processDefintionId");
	var rule_id=$(this).attr("rule_id");
	var activity_id=$(this).attr("activity_id");
	console.log("status------>"+status);
	if(status==1){
		suspend(market_id, processDefintionId);
	}else{
		activte(market_id, processDefintionId,rule_id,activity_id);
	}
});

//启用活动
function activte(market_id,processDefintionId,rule_id,activity_id) {
	var url = "<%=path%>/api/smart_market/activate";
	var manageId="#manageId"+market_id;
	$.post(url, {
		"access_token" : access_token,
		"cid" : cid,
		"uid" : uid,
		"market_id" : market_id,
		"processDefintionId" : processDefintionId,
		"rule_id" : rule_id,
		"activity_id" : activity_id,
	}, function(data) {
		
		var datas = JSON.parse(data);
		if (datas.error_code == "0") {
			$(manageId).text("停用");
			$(manageId).attr("status","1");
			$(manageId).css("color","#03a9f4");
			showDialog("启用成功");
		} else {
			showDialog(datas.error_msg);
		}
	});
}
//停止活动
function suspend(market_id, processDefintionId) {
	var url = "<%=path%>/api/smart_market/suspend";
	var manageId="#manageId"+market_id;
	$.post(url, {
		"access_token" : access_token,
		"cid" : cid,
		"uid" : uid,
		"market_id" : market_id,
		"processDefintionId" : processDefintionId,
	}, function(data) {
		var datas = JSON.parse(data);
		if (datas.error_code == "0") {
			$(manageId).text("启用");
			$(manageId).attr("status","2");
			$(manageId).css("color","#ff7469");
			showDialog("停用成功");
		} else {
			showDialog("启用失败");
		}
	});
}

//删除
function deleteActivity(activity_id) {
	$(".j_popup_box").show();
	$(".j_popup_box .j_popup_box_confirm").unbind("click");
	$(".j_popup_box .j_popup_box_confirm").one("click",function(){
		var url = "${pageContext.request.contextPath}/activity/delete";
		var lineId="#line"+activity_id;
		$.post(url, {
			"access_token" : access_token,
			"cid" : cid,
			"uid" : uid,
			"activity_id" : activity_id,
		}, function(data) {
			var datas = JSON.parse(data);
			if (datas.error_code == 0) {
				alert("删除成功");
				$(lineId).remove();
				$(".j_popup_box").hide();
			} else {
				alert("删除失败");
			}
		});
	});
}

function findByCustomerId(id){
	customerId = id;
	$.post(path+'/api/custome/findByCustomerId', {
		"customerID" : id,
	}, function(data) {
		data = JSON.parse(data);
		if(data.bcCustomer != 0){
			resetCustomer();
			$("#namea").val(isnull(data.bcCustomer.name));
			$("#phonea").val(isnull(data.bcCustomer.phone));
			$("#emaila").val(isnull(data.bcCustomer.email));
			$("#companya").val(isnull(data.bcCustomer.company));
			$("#joba").val(isnull(data.bcCustomer.job));
			$("#remarksa").val(isnull(data.bcCustomer.remarks));
			$("#gendera").val(isnull(data.bcCustomer.gender));
			$("#birthdaya").val(isnull(data.bcCustomer.birthday));
			$("#weiboa").val(isnull(data.bcCustomer.weibo));
			$("#qqa").val(isnull(data.bcCustomer.bak1));
			$("#wechata").val(isnull(data.bcCustomer.wechat));
			$("#addressa").val(isnull(data.bcCustomer.address));
			$("#citya").val(isnull(data.bcCustomer.city));
			$("#faxa").val(isnull(data.bcCustomer.fax));
			$("#taga").val(isnull(data.bcCustomer.tag));
			$("#customerID").val(id);
		}else{
			alert("编辑查询失败,未获取客户标识！")
		}
	});
	$('.j_customerEdit').addClass('show');
}

function saveOrUpdate(){
	var cID = customerId;
	var myregPhone  = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
	var myregEmail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if($("#phonea").val() == '' || $("#phonea").val() == null){
		alert('手机号码不能为空！'); 
	    return false; 
	}else{
		if(!myregPhone.test($("#phonea").val()))  { 
		    alert('请输入有效的手机号码！'); 
		    return false; 
		}
	}
	if( $("#emaila").val() == '' || $("#emaila").val() == null){
		
	}else{
		if(!myregEmail.test($("#emaila").val()))  { 
		    alert('请输入正确的邮箱！'); 
		    return false; 
		}
	}
	if(cID != ''){
		editCustomer(cID);
	}
}

//修改客户资料
function editCustomer(cID){
	$.post(path+'/api/custome/editCustomer', {
		"customerID" : cID,
		"name" : $("#namea").val(),
		"phone" : $("#phonea").val(),
		"email" : $("#emaila").val(),
		"company" : $("#companya").val(),
		"job" : $("#joba").val(),
		"remarks" : $("#remarksa").val(),
		"gender" : $("#gendera").val(),
		"birthday" : $("#birthdaya").val(),
		"weibo" : $("#weiboa").val(),
		"qq" : $("#qqa").val(),
		"wechat" : $("#wechata").val(),
		"city" : $("#citya").val(),
		"fax" : $("#faxa").val(),
		"tag" : $("#taga").val(),
		"address" : $("#addressa").val(),
	}, function(data) {
		$('.j_customerEdit').removeClass('show');
		init();
		alert(data.message);
	});
}
//判断是否为空
function isnull(str){
	if(str == null ){
		return '';
	}else{
		return str;
	}
}
function resetCustomer(){
	$("#namea").val('');
	$("#phonea").val('');
	$("#emaila").val('');
	$("#companya").val('');
	$("#joba").val('');
	$("#remarksa").val('');
	$("#gendera").val('');
	$("#birthdaya").val('');
	$("#weiboa").val('');
	$("#qqa").val('');
	$("#wechata").val('');
	$("#addressa").val('');
	$("#citya").val('');
	$("#faxa").val('');
	$("#taga").val('');
	$("#customerID").val('');
}


var couponId;
var coupon_code;
var activity_id;
var customer_id;


  $('#bm_qux').click(function(){
	  $('.s_popup,.issue').hide(); 
  });
  $('.issue > span').click(function(){
      $('.s_popup,.issue').hide();
    });
 //----------->反核销
$(document).on('click','.k_fhx',function(){	
   couponId = $(this).attr("couponId");
   coupon_code = $(this).attr("cd");
   activity_id = $(this).attr("acid"); 
   customer_id = $(this).attr("cuid");
	   $('.s_popup,.issue').show();
	   $('#bm_fanhe').val('');
   $('#bm_cao').val(user_name);  
});


//----------->反核销成功
var reverse_reason;
//var reverse_name;
$('#bm_fanque').click(function(){
	reverse_reason = $('#bm_fanhe').val();
    //reverse_name = $('#bm_cao').val();
//	activity_name = $(this).attr("acname");
    if(StringEmpty(reverse_reason)){
    	cancelVerification();
    }else if(!StringEmpty(reverse_reason)){
    	showDialog("请输入反核销原因！！！");
    }
});


function cancelVerification(){
   console.log("coupon_id----》"+couponId);
   var url="<%=path%>/verification/reverse";
	$.post(url, {
		"access_token" : access_token,
		"cid" : cid,
		"uid" : uid,
		"reverse_reason" : reverse_reason,
		"coupon_id" : couponId,
		"reverse_name" : user_name,	      
	//	"activity_name" : activity_name,
		"customer_id" : customer_id,
		"activity_id" : activityId
	}, function(data) {
		var datas = JSON.parse(data);
		console.log("-------->"+datas.error_code);
		if (datas.error_code == 0) {
			 if(datas.error_code == "0"){
            		//反核销信息确认
         			$('.s_popup,.issue').hide();
            		$('.s_popup1,.issue1').show();
            		var str = "";
            		str += '<i>编码为</i><p>' +coupon_code+ '</p><em>优惠券反核销成功！</em>';
            		$('#s_cc').html(str);	 
            	 }else if(data.error_code == "5"){
            		showDialog("请勿重复反核销"); 
            		$('.s_popup,.issue').hide();	
            		$('.s_popup1,.issue1').hide();
            	 }else if(data.error_code == "2"){
            		 showDialog("请填写信息！！！");
            		 $('.s_popup,.issue').show();
            	 }            	
		} else {
		}
	});
}

$('.s_finish').click(function(){
	//  window.location.reload();
	  var ssid = '#writeOffLine'+coupon_code;
	  $('.s_popup1,.issue1').hide();
	  $('.s_popup,.issue').hide();
	  $(ssid).remove();
});

//判断字符串是否为空
function StringEmpty(content) {
	if (content == undefined || content == "" || content == null) {
		return false;
	} else {
		return true;
	}
}
</script>
</html>